/** *******************************************************************
 * FlexDatabaseManager
 * Copyright (c) 2008 Jonnie Spratley. All Rights Reserved.
 * @author  Jonnie Spratley
 * @contact jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.flexdatabasemanager.vo
{
	import com.jonniespratley.flexdatabasemanager.utils.*;
	
	[Bindable]
	public class TableStatusVO extends Object
	{
		public var aName:String;
		public var aEngine:String;
		public var aVersion:String;
		public var aRowFormat:String;
		public var aRows:String;
		public var aAvgRowLength:String;
		public var aDataLength:String;
		public var aMaxDataLength:String;
		public var aIndexLength:String;
		public var aDataFree:String;
		public var aAutoIncrement:String;
		public var aCreated:String;
		public var aUpdated:String;
		public var aChecked:String;
		public var aCollation:String;
		public var aChecksum:String;
		public var aCreateOptions:String;
		public var aComment:String;
		
		public var aType:String;
		
		public function  TableStatusVO( obj:Object = null )
		{	
			if ( obj != null )
			{
				this.aName = obj['Name'];
				this.aEngine = obj['Engine'];
				this.aVersion = obj['Version'];
				this.aRowFormat = obj['Row_format'];
				this.aRows = obj['Rows'];
				this.aAvgRowLength = obj['Avg_row_length'];
				this.aDataLength = obj['Data_length'];
				this.aMaxDataLength = obj['Max_data_length'];
				this.aIndexLength = obj['Index_length'];
				this.aDataFree = obj['Data_free'];
				this.aAutoIncrement = obj['Auto_increment'];
				this.aCollation = obj['Collation'];				
				this.aChecksum = obj['Checksum'];
				this.aCreateOptions = obj['Create_options'];
				this.aComment = obj['Comment'];				
				this.aType = 'status';	
				
				this.aCreated = FlexDataManagerUtils.formatMySQLDate( obj['Create_time'], 'date', '.' ); 
				this.aUpdated = FlexDataManagerUtils.formatMySQLDate( obj['Update_time'], 'date', '.' );
				this.aChecked = FlexDataManagerUtils.formatMySQLDate( obj['Check_time'], 'date', '.' );
			} 
		}
		
		public function get label():String
		{
			return aName;
		}
		
		public function get tableName():String
		{
			return aName;
		}
		
		public function get indexSize():String
		{
			return aIndexLength;
		}
		
		public function get dataSize():String
		{
			return aDataLength;
		}
		
		public function get freeSize():String
		{
			return aDataFree;
		}
		
		public function get totalSize():String
		{
			var indexSz:Number = Number( aIndexLength );
			var dataSz:Number = Number( aDataLength );
			var total:Number = indexSz + dataSz;
			
			return String( total );
		}
		
		private function formatSize( oldSize:String, newSizeType:int ):String
		{
			var byteUtil:ByteUtils = new ByteUtils();
			var formatted:String = byteUtil.format( Number( oldSize ), newSizeType, 2 );
				
			return formatted;
		}
	}
}